<template>
	<view class="main">
		<view class="job_content">
			<view class="job_list">
				<view class="">
					{{TopContent.createTime}}
				</view>
				<view class="job_title">
					<!-- <view class="job_title_icon">定时</view> -->
					<view class="base_icon zhouqi"
						:class="{'zhouqi':TopContent.jobType == 2,'dingshi':TopContent.jobType == 1}">
						{{TopContent.jobType == 1 ? '定时' : '周期'}}
					</view>
					<view class="m-l-8">
						{{TopContent.jobName}}
					</view>
				</view>
				<view class="" v-if="TopContent.targetCustomerName">
					目标患者：{{TopContent.targetCustomerName}}
				</view>
				<view class="">
					{{TopContent.jobContent}}
				</view>
				<view class="job_action" @click="goWenJuan">
					<view class="job_left">
						{{UrlTitle ? UrlTitle+'回访问卷详情' : '暂无问卷详情' }}
					</view>
					<view class="job_right">
						<u-icon name="arrow-right" size="38rpx"></u-icon>
					</view>
				</view>
			</view>

			<view class="input_bg">
				<u-input v-model="value" style="input_position" type="textarea" placeholder="请输入综合评估" :border="false"
					:maxlength="limit" />
				<view class="tips">
					{{value.length}}/{{limit}}
				</view>
			</view>
			<go-nav></go-nav>

		</view>
		<view style="width: 100%;">
			<bottom-button text="确定" @confirm="confirm"></bottom-button>
		</view>
	</view>
</template>

<script>
	import {
		getPingguDetails,
		updateFollowupPlanJobRecord,
		pingguUrl
	} from '@/api/index.js'
	export default {
		data() {
			return {
				value: '',
				limit: 300,
				id: '',
				externalUserId: '',
				planId: '',
				TopContent: {
					createTime: '',
					jobType: 1,
					jobName: '',
					jobContent: ''
				},
				UrlTitle: '',
				jumUrl: '',
				quesResultId: ''
			}
		},
		async onLoad(obj) {
			if (obj.id) {
				this.id = obj.id
				this.getDetils()
			}
			if (obj.externalUserId) {
				this.externalUserId = obj.externalUserId
			}
			if (obj.planId) {
				this.planId = obj.planId
			}
			if (obj.quesResultId) {
				this.quesResultId = obj.quesResultId
			}
			//有本地缓存中的数据，说明是首页带过来的
			//console.log(uni.getStorageSync('PINGGUDETAILS'));
			if (uni.getStorageSync('PINGGUDETAILS')) {
				this.TopContent = uni.getStorageSync('PINGGUDETAILS')
				this.getUrl()
			}
			//回访url

		},
		methods: {
			goWenJuan() {
				if (this.jumUrl) {
					window.location.href = this.jumUrl
				}
			},
			async getUrl() {
				const params = {
					quesTemplateId: this.TopContent.quesTemplateId,
				}
				if (this.quesResultId) {
					params.quesResultId = this.quesResultId  //有quesResultId说明是从患者带来的
				} else {
					params.quesResultId = this.TopContent.quesResultId //否则是首页过来的
				}
				let res = await pingguUrl(params)
				this.UrlTitle = res.quesTemplateTitle
				this.jumUrl = res.quesShowUrl
				//console.log(res);
			},
			async confirm() {
				let params = {}
				if (this.id) {
					params.externalUserId = this.externalUserId
					params.planId = this.planId
					params.planJobId = this.id
					params.recordDesc = this.value
				} else { //从vuex里取
					params.externalUserId = this.TopContent.externalUserId
					params.planId = this.TopContent.planId
					params.planJobId = this.TopContent.id
					params.recordDesc = this.value
				}
				let res = await updateFollowupPlanJobRecord(params)
				if (res.code == 200) {
					this.$u.toast(res.msg, 3000)
					setTimeout(() => {
						// uni.switchTab({
						// 	url:'/pages/index/index'
						// })
						uni.navigateBack({
							delta: 1
						})
					}, 2000)

				}
			},
			async getDetils() { //患者详情过来的
				let res = await getPingguDetails(this.id)
				this.TopContent = res.data
				this.getUrl()
				//console.log(res);
			}
		},
	}
</script>

<style lang="scss" scoped>
	.main {
		background-color: #F8F8F8;
		min-height: 100vh;

		.job_content {
			background-color: #f8f8f8;
			margin: 0 24rpx 8rpx 24rpx;
			border-radius: 20rpx;
			padding-bottom: 150rpx;
			padding-top: 24rpx;

			.job_list {
				background-color: white;
				padding: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-size: 32rpx;
				color: #999999;
				line-height: 1.5;
				margin-bottom: 20rpx;
				border-radius: 20rpx;

				.job_title {
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 36rpx;
					color: #212121;
					line-height: 1.5;
					display: flex;
					align-items: center;

					.job_title_icon {
						padding: 0 8rpx;
						background: #4DC0D9;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #FFFFFF;
						line-height: 36rpx;
						margin-right: 16rpx;
					}

					.base_icon {
						display: flex;
						align-items: center;
						justify-content: center;
						padding: 4rpx 6rpx 6rpx 6rpx;
						width: 70rpx;
						height: 40rpx;
						background: #FF8D07;
						font-weight: 500;
						font-size: 24rpx;
						color: #FFFFFF;
						text-align: center;
						line-height: 28rpx;
						border-radius: 8rpx;
					}

					.zhouqi {
						background: #FF8D07;
					}

					.dingshi {
						background-color: #4DC0D9;
					}

					.yellow {
						background-color: #FF8D07;
					}
				}
			}

			.job_action {
				margin-top: 24rpx;
				display: flex;
				color: #4DC0D9;
				justify-content: space-between;

				.job_left {
					margin-right: 48rpx;
				}
			}
		}

		.input_bg {
			background-color: white;
			border-radius: 20rpx;

			.tips {
				display: flex;
				justify-content: flex-end;
				padding-right: 24rpx;
				padding-bottom: 24rpx;
				color: #C1C1C1;
				font-size: 30rpx;
			}

		}
	}

	::v-deep .u-input__input {
		padding-top: 24rpx;
		padding-left: 24rpx;
		font-size: 34rpx !important;
	}
</style>